package net.alteiar.ui.algorithms;

import java.awt.image.BufferedImage;

import net.alteiar.algorithms.CannyEdgeDetector;
import net.alteiar.images.BasicImage;
import net.alteiar.images.IDrawable;

public class AlgorithmEdgeDetector implements Algorithm {

	private final CannyEdgeDetector detector;

	public AlgorithmEdgeDetector() {
		detector = new CannyEdgeDetector();
	}

	public float getLowThreshold() {
		return detector.getLowThreshold();
	}

	public void setLowThreshold(float lowThreshold) {
		detector.setLowThreshold(lowThreshold);
	}

	public float getHighThreshold() {
		return detector.getHighThreshold();
	}

	public void setHighThreshold(float threshold) {
		this.detector.setHighThreshold(threshold);
	}

	public boolean isContrastNormalized() {
		return detector.isContrastNormalized();
	}

	public void setContrastNormalized(boolean contrastNormalized) {
		detector.setContrastNormalized(contrastNormalized);
	}

	public int getGaussianKernelWidth() {
		return detector.getGaussianKernelWidth();
	}

	public void setGaussianKernelWidth(int gaussianKernelWidth) {
		detector.setGaussianKernelWidth(gaussianKernelWidth);
	}

	public float getGaussianKernelRadius() {
		return detector.getGaussianKernelRadius();
	}

	public void setGaussianKernelRadius(float gaussianKernelRadius) {
		detector.setGaussianKernelRadius(gaussianKernelRadius);
	}

	@Override
	public IDrawable execute(BasicImage img) {
		BufferedImage org = img.getImage();

		// apply it to an image
		detector.setSourceImage(org);
		detector.process();
		BufferedImage edges = detector.getEdgesImage();

		return new BasicImage(edges);
	}

	@Override
	public String toString() {
		return "Edge detector";
	}

}
